package com.example.administrator.waitan.find;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.util.LruCache;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;
import com.example.administrator.waitan.R;
import com.example.administrator.waitan.tools.VolleySingleton;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/1/13.
 */
public class LookTodayRecyclerViewAdapter extends RecyclerView.Adapter<LookTodayRecyclerViewAdapter.MyViewHolder> {
    private Context context;
    private List<LookTodayInfo> data;
    private ImageLoader imageLoader;
    private ImageLoader.ImageCache imageCache;
    private LruCache<String, Bitmap> lruCache;
    private RequestQueue queue;

    public LookTodayRecyclerViewAdapter(Context context, List<LookTodayInfo> data) {
        this.context = context;
        if(data!=null){
        this.data = data;
        }else {
            this.data = new ArrayList<>();
        }
    }

    public void initData(){

    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_rc_looktoday, parent, false);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.title.setText(data.get(position).getAuthor_name());
        ImageLoader.ImageListener listener = ImageLoader.getImageListener(holder.pic, R.mipmap.mi_icon, R.mipmap.mi_icon);
        VolleySingleton.getImageLoader().get(data.get(position).getThumbnail(), listener);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        ImageView pic;
        TextView title;

        public MyViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.tv_item_lookToday_title);
            pic = (ImageView) itemView.findViewById(R.id.iv_item_lookToday_pic);
        }
    }
}
